Here's a very common pattern. People recommend it everywhere. Put your config into a separate file, and require
it in your script. Awesome, right!?
Halfway. Yes, doing it is better than not. BUT now you have a bunch of invisible variables in your script! This makes for code that is hard to read and debug, and is fragile because code that directly affects your script is far away from it.
Imagine you got a warning like "undefined index 'foo' …" one day. It seems obvious now — the config file is messed up. But what if there were a ton of other stuff going on around this? What if this happens six months later (when you've completely forgotten about where $config
comes from)? Even worse, what if a second config file gets included somewhere in the same scope and these invisible variables start colliding!?
BAD.config.php
<?php
$config["foo"] = "Hello, World!";